//
//  SkinSettingViewController.m
//  CPICMobileServiceApp
//
//  Created by sinosoft on 13-2-27.
//  Copyright (c) 2013年 lizhiwei. All rights reserved.
//

#import "SkinSettingViewController.h"
#import "RCAlertViewUtil.h"
#import "CustomActionSheet.h"
#import "ViewController.h"
#import "AppDelegate.h"
#import "SkinUpdateInterface.h"
#import "Config.h"
#import "UIImageView+WebCache.h"
#import "NSString+SBJson.h"
#import "NSObject+SBJson.h"

#define UserDefaultBgKindKey @"UserDefaultBgKindKey"

@interface SkinSettingViewController ()

@end

@implementation SkinSettingViewController
@synthesize TableViewSkin;
@synthesize swichAutoStyle;
@synthesize PreviewImage;
@synthesize SkinType;
@synthesize progress;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.title=@"主题风格设置";
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    NSString *bgimage= [accountDefaults objectForKey:@"UserDefaultBgKindKey"];
    NSLog(@"HEHEHEHEH");
    
    if ([bgimage isEqualToString:@"蓝色主题风格"]) 
    {
        ADD_BACKGROUND_BUTTONITEM(@"icon640X88@2x.png");
        ADD_LEFT_BUTTONITEM(@"back.png");
        ADD_TITLE_NAMEITEM(@"皮肤设置");
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773@2x"]];
    }
    else if([bgimage isEqualToString:@"棕色主题风格"])
    {
        ADD_BACKGROUND_BUTTONITEM(@"icon640X88_01@2x.png");
        ADD_LEFT_BUTTONITEM(@"back_01.png");
        ADD_TITLE_NAMEITEM(@"皮肤设置");
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773_01@2x"]];
    }
    else if([bgimage isEqualToString:@"重大节日皮肤"])
    {
        NSData *dataImg_02=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_02];
        NSLog(@"-------找到%@",dataImg_02);
        NSData *dataImg_03=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_03];
        NSData *dataImg_04=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_04];
        
        NSURL *urlSkinImg_02=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_02]];
        NSURL *urlSkinImg_03=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_03]];
        NSURL *urlSkinImg_04=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_04]];
        NSLog(@"-------找到333%@",urlSkinImg_02);
         
        UIImageView * LogoImage = [[UIImageView alloc]init];
        [LogoImage setImageWithURL:urlSkinImg_03 success:^(UIImage *image)
         {
             imgData=UIImagePNGRepresentation(LogoImage.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_03];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        LogoImage.image = [UIImage imageWithData:dataImg_03];
        LogoImage.frame = CGRectMake(0, 0, LogoImage.image.size.width/2, LogoImage.image.size.height/2);
        [self.view addSubview:LogoImage];
        
        //--------------------------
        UIButton * CallOutBtn1 = [UIButton buttonWithType:UIButtonTypeCustom];
        CallOutBtn1.frame = CGRectMake(10, 10, 109/2, 57/2);
        UIImageView * Back = [[UIImageView alloc]init];
        [Back setImageWithURL:urlSkinImg_02 success:^(UIImage *image)
         {
             imgData=UIImagePNGRepresentation(Back.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_02];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        [Back setImage:[UIImage imageWithData:dataImg_02]];
        [CallOutBtn1 setImage:Back.image forState:UIControlStateNormal];
        [CallOutBtn1 addTarget:self action:@selector(ClickCallOutBtn) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:CallOutBtn1];
        //--------------------------
        
        ADD_TITLE_NAMEITEM(@"皮肤设置");
        
        
        UIImageView *bgimage = [[UIImageView alloc]initWithFrame:CGRectMake(0,44, self.view.frame.size.width, self.view.frame.size.height-44)];
        [bgimage setImageWithURL:urlSkinImg_04 success:^(UIImage *image)
         {
             imgData=UIImagePNGRepresentation(bgimage.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_04];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        [bgimage setImage:[UIImage imageWithData:dataImg_04]];
        [self.view addSubview:bgimage];
        [bgimage release];
    }
    
    arrStyleID=[[NSMutableArray alloc]init];
    arrStyleName=[[NSMutableArray alloc]init];
    //皮肤类型
    SkinType = [[NSMutableArray alloc]initWithObjects:@"蓝色主题风格",@"棕色主题风格",nil];
    
    //添加UITableview
    TableViewSkin = [[UITableView alloc]initWithFrame:CGRectMake(13, 62, 310, 300) style:UITableViewStyleGrouped];
	TableViewSkin.delegate = self;
	TableViewSkin.dataSource = self;
    
    TableViewSkin.opaque = NO;
    TableViewSkin.backgroundView = nil;
    TableViewSkin.autoresizingMask = UIViewContentModeTop;
    TableViewSkin.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
    TableViewSkin.scrollEnabled=NO;
    TableViewSkin.backgroundColor=[UIColor clearColor];
    //[TableViewUser reloadData];
	[self.view addSubview:TableViewSkin];
    
    PreviewImage= [[UIImageView alloc]init];
    PreviewImage.image = [UIImage imageNamed:@"skin_stye.png"];
    PreviewImage.frame = CGRectMake((self.view.frame.size.width-PreviewImage.image.size.width)/2, 254, PreviewImage.image.size.width, PreviewImage.image.size.width);
    [self.view addSubview:PreviewImage];
    
    UILabel *lblPreview=[[UILabel alloc]initWithFrame:CGRectMake((self.view.frame.size.width-150)/2, 380, 150, 50)];
    lblPreview.text=@"主题风格预览";
    lblPreview.backgroundColor=[UIColor clearColor];
    lblPreview.textAlignment = UITextAlignmentCenter;
    lblPreview.textColor = [UIColor whiteColor];
    lblPreview.font = [UIFont systemFontOfSize:14.0];
    [self.view addSubview:lblPreview];
    [lblPreview release];
}
-(void) ClickCallOutBtn
{

    NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    if ([swichAutoStyle isOn])
    {
        [accountDefaults setObject:@"1" forKey:@"IF_SKIN_UPDATE"];
        [accountDefaults synchronize];
    }
    else
    {
        [accountDefaults setObject:@"0" forKey:@"IF_SKIN_UPDATE"];
        [accountDefaults synchronize];
    }
    
    ViewController * home = [[ViewController alloc]init];
    [AppDelegate app].unc =nil;
    [AppDelegate app].unc = [[UINavigationController alloc] initWithRootViewController:home];
    [[AppDelegate app].window addSubview:[AppDelegate app].unc.view];
    [[AppDelegate app].window makeKeyAndVisible];
    [[AppDelegate app].unc popViewControllerAnimated:YES];
}
- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

#pragma UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *Identifier=@"Identifier";
    UITableViewCell *cell=(UITableViewCell *)[TableViewSkin dequeueReusableCellWithIdentifier:Identifier];
    if(indexPath.row==1)
    {
        if (cell==nil)
        {
            cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Identifier]autorelease];
            cell.accessoryType = UITableViewCellAccessoryNone;
            cell.selectionStyle=UITableViewCellSelectionStyleNone;//选中后颜色没变化
            //cell.backgroundColor = [UIColor clearColor];
            UILabel *lblAutoStyle=[[UILabel alloc]initWithFrame:CGRectMake(20, 14.5, 210, 21)];
            lblAutoStyle.backgroundColor=[UIColor clearColor];
            lblAutoStyle.text=@"节假日自动更换主题风格";
            lblAutoStyle.font = [UIFont systemFontOfSize:14.0];
            [cell addSubview:lblAutoStyle];
            [lblAutoStyle release];
            
            swichAutoStyle=[[UISwitch alloc]initWithFrame:CGRectMake(210, 10, 90, 38)];
            [swichAutoStyle addTarget:self action:@selector(CheckIfAuto) forControlEvents:UIControlEventTouchUpInside];
            [cell addSubview:swichAutoStyle];
            
            NSUserDefaults *accountDefaults1 = [NSUserDefaults standardUserDefaults];
            //NSString *strSkin=[accountDefaults1 valueForKey:@"IF_SKIN_UPDATE"];
            NSString *strSkin=[accountDefaults1 valueForKey:@"SKIN_SWITCH_STATUS"];
            if ([[accountDefaults1 valueForKey:@"SKIN_SWITCH_STATUS"]isEqualToString:@"0"])
            {
                [swichAutoStyle setOn:NO];
            }
            else if([strSkin isEqualToString:@"1"])
            {
                [swichAutoStyle setOn:YES];
            }
            else
            {
                [swichAutoStyle setOn:NO];
            }
        }
    }
    else
    {
        if (cell==nil)
        {
            cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Identifier]autorelease];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//右边有个详细指向箭头
            cell.selectionStyle=UITableViewCellSelectionStyleBlue;//选中后颜色没变化
            
            if(indexPath.row==0)
            {
                UILabel *lblStyle=[[UILabel alloc]initWithFrame:CGRectMake(20, 14.5, 150, 21)];
                lblStyle.backgroundColor=[UIColor clearColor];
                lblStyle.text=@"选择主题风格";
                lblStyle.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:lblStyle];
                [lblStyle release];
            }
            else if(indexPath.row==2)
            {
                UILabel *lblAutoStyle=[[UILabel alloc]initWithFrame:CGRectMake(20, 14.5, 180, 21)];
                lblAutoStyle.backgroundColor=[UIColor clearColor];
                lblAutoStyle.text=@"下载最新的主题风格";
                lblAutoStyle.font = [UIFont systemFontOfSize:14.0];
                [cell addSubview:lblAutoStyle];
                [lblAutoStyle release];
                
            }
        }
    }
    

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0)
    {
        CustomActionSheet *sheet=[[CustomActionSheet alloc]initWithHeight:284.0f WithSheetTitle:@"" WithDataArray:SkinType];
        sheet.Customdelegate = self;
        sheet.tag = 0;
        [sheet showInView:self.view];
    }
    else if(indexPath.row == 2)
    {
//         SkinUpdateInterface * updateSkin = [[SkinUpdateInterface alloc]initWithFrame:CGRectMake((self.view.frame.size.width-150)/2, (self.view.frame.size.height-150)/2, 150, 150)];
//         [updateSkin setSkinUpdateRequest];
//         [self.view addSubview:updateSkin];
        
        [self setSkinListRequest];
    }
}

-(void)setSkinListRequest
{
//    NSString *strRequestCode=@"RequestCode=61101";
    NSMutableDictionary *dicRequest = [NSMutableDictionary dictionary];
    [dicRequest setObject:@"admin" forKey:@"userAccount"];
    NSString *strRequestJson=[dicRequest JSONRepresentation];
//    strRequestJson=[NSString stringWithFormat:@"&RequestData=%@",strRequestJson];
//    NSString *strUrl=[NSString stringWithFormat:@"%@%@%@",Server_Url,strRequestCode,strRequestJson];
//    NSString *strUrlEncod = [strUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];//字符串编码转换
//    NSURL *myurl = [NSURL URLWithString:strUrlEncod];//This method expects URLString to contain any necessary percent escape codes, which are ‘:’, ‘/’, ‘%’, ‘#’, ‘;’, and ‘@’. Note that ‘%’ escapes are translated via UTF-8.
//    NSLog(@"皮肤主题风格请求报文为:%@",strUrl);
    ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:Server_Url_Form]];
    
    //设置需要POST的数据，这里提交两个数据，A=a&B=b
    [request setPostValue:@"61101" forKey:@"RequestCode"];
    [request setPostValue:strRequestJson forKey:@"RequestData"];
    
    [request setDelegate:self];
    [request setDidFailSelector:@selector(ResponseSkinListFail:)];
    [request setDidFinishSelector:@selector(ResonseSkinListSuccess:)];
    [request startAsynchronous];
    
    showProgress = YES;
    if (showProgress)
    {
        progress= [[MBProgressHUD alloc]initWithView:self.view];
        [self.view addSubview:progress];
        [self.view bringSubviewToFront:progress];
        progress.labelText = @"加载中...";
        [progress show:NO];
        showProgress = NO;
        [progress setHidden:YES];
    };
}

- (void)ResonseSkinListSuccess:(ASIHTTPRequest *)request
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    NSString *responseString = [request responseString];
    NSLog(@"responseString %@",responseString);
    NSMutableDictionary *dictResponse=[responseString JSONValue];
    NSLog(@"dictResponse  %@",dictResponse);
    
    NSMutableDictionary *jsonoSubObj = [dictResponse objectForKey:@"head"];
    NSString * ss = [[NSString alloc] initWithFormat:@"%@",[jsonoSubObj objectForKey:@"success"]];
    [arrStyleName removeAllObjects];
    [arrStyleID removeAllObjects];
    if ([ss isEqualToString:@"1"])
    {
        NSMutableDictionary *dictList=[dictResponse objectForKey:@"themeStyleList"];
        NSMutableArray *arrData=[dictList valueForKey:@"data"];
        for (int i=0; i<[arrData count]; i++) {
            NSMutableDictionary *dictItem=[arrData objectAtIndex:i];
            NSString *strStyleID=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"styleID"]];
            NSString *strStyleName=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"styleName"]];
            [arrStyleID addObject:strStyleID];
            [arrStyleName addObject:strStyleName];
            [strStyleID release];
            [strStyleName release];
        }
        if (arrStyleName!=0) {
            CustomActionSheet *sheet=[[CustomActionSheet alloc]initWithHeight:284.0f WithSheetTitle:@"" WithDataArray:arrStyleName];
            sheet.Customdelegate = self;
            sheet.tag = 1;
            [sheet showInView:self.view];
        }
    }
    else
    {
        [self justShowMessage:@"皮肤主题风格列表为空！" title:@"提示"];
    }
    [ss release];
}

- (void)ResponseSkinListFail:(ASIHTTPRequest *)request
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    NSLog(@"服务器连接失败!");
    [self justShowMessage:@"服务器连接失败" title:@"注意"];
}
-(void)setSkinUpdateRequest:(NSInteger)selectIndex
{
    NSString *strStyleID;
    if ([arrStyleID count]>selectIndex) {
        strStyleID=[arrStyleID objectAtIndex:selectIndex];
    }
    else
    {
        strStyleID=@"";
    }
//    NSString *strRequestCode=@"RequestCode=61201";
    NSMutableDictionary *dicRequest = [NSMutableDictionary dictionary];
    [dicRequest setObject:@"admin22" forKey:@"userAccount"];
    [dicRequest setObject:strStyleID forKey:@"styleID"];
    NSString *strRequestJson=[dicRequest JSONRepresentation];
//    strRequestJson=[NSString stringWithFormat:@"&RequestData=%@",strRequestJson];
//    NSString *strUrl=[NSString stringWithFormat:@"%@%@%@",Server_Url,strRequestCode,strRequestJson];
//    NSString *strUrlEncod = [strUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];//字符串编码转换
//    NSURL *myurl = [NSURL URLWithString:strUrlEncod];//This method expects URLString to contain any necessary percent escape codes, which are ‘:’, ‘/’, ‘%’, ‘#’, ‘;’, and ‘@’. Note that ‘%’ escapes are translated via UTF-8.
//    NSLog(@"皮肤主题风格设置接口请求报文为:%@",strUrl);
    ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:Server_Url_Form]];
    
    //设置需要POST的数据，这里提交两个数据，A=a&B=b
    [request setPostValue:@"61201" forKey:@"RequestCode"];
    [request setPostValue:strRequestJson forKey:@"RequestData"];
    
    [request setDelegate:self];
    [request setDidFailSelector:@selector(ResponseUpdateFail:)];
    [request setDidFinishSelector:@selector(ResonseUpdateSuccess:)];
    [request startAsynchronous];
    
    showProgress = YES;
    if (showProgress)
    {
        progress= [[MBProgressHUD alloc]initWithView:self.view];
        [self.view addSubview:progress];
        [self.view bringSubviewToFront:progress];
        progress.labelText = @"加载中...";
        [progress show:NO];
        showProgress = NO;
        [progress setHidden:YES];
    };
}

- (void)ResonseUpdateSuccess:(ASIHTTPRequest *)request
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    NSString *responseString = [request responseString];
    NSLog(@"responseString %@",responseString);
    NSMutableDictionary *dictResponse=[responseString JSONValue];
    NSLog(@"dictResponse  %@",dictResponse);
    
    NSMutableDictionary *jsonoSubObj = [dictResponse objectForKey:@"head"];
    NSString * ss = [[NSString alloc] initWithFormat:@"%@",[jsonoSubObj objectForKey:@"success"]];

    if ([ss isEqualToString:@"1"])
    {
        DicthemeStyleSetting = [dictResponse objectForKey:@"themeStyleSettingList"];
        ArraythemeStyleSetting=[DicthemeStyleSetting objectForKey:@"data"];
        NSLog(@"-------------%@",ArraythemeStyleSetting);
        
        for (int k = 0; k < [ArraythemeStyleSetting count]; k++)
        {
            NSMutableDictionary * dicskin = [ArraythemeStyleSetting objectAtIndex:k];
            NSString * stylePicName=[[NSString alloc] initWithFormat:@"%@",[dicskin objectForKey:@"stylePicName"]];
            
            if ([stylePicName isEqualToString:@"main_bg.png"])
            {

                NSString *strMainURL=[[NSString alloc]initWithFormat:@"%@",[dicskin objectForKey:@"stylePicId"]];
                stylePicNameUrl=[NSString stringWithFormat:@"%@%@",Image_Url,strMainURL];
                stylePicNameUrl = [stylePicNameUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];//字符串编码转换
                [[NSUserDefaults standardUserDefaults] setObject:stylePicNameUrl forKey:SKIN_IMG_URL_01];
                [strMainURL release];
            }
            else if([stylePicName isEqualToString:@"back.png"])
            {
                //NSString * stylePicId = @"4028818f3da54bed013da58de1e80002";
                NSString *strBackURL=[[NSString alloc]initWithFormat:@"%@",[dicskin objectForKey:@"stylePicId"]];
                stylePicNameUrl=[NSString stringWithFormat:@"%@%@",Image_Url,strBackURL];
                stylePicNameUrl = [stylePicNameUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];//字符串编码转换
                [[NSUserDefaults standardUserDefaults] setObject:stylePicNameUrl forKey:SKIN_IMG_URL_02];
                [strBackURL release];
            }
            else if([stylePicName isEqualToString:@"icon.png"])
            {
                //NSString * stylePicId = @"4028818f3da54bed013da58e44c80003";
                NSString *strIconURL=[[NSString alloc]initWithFormat:@"%@",[dicskin objectForKey:@"stylePicId"]];
                stylePicNameUrl=[NSString stringWithFormat:@"%@%@",Image_Url,strIconURL];
                stylePicNameUrl = [stylePicNameUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];//字符串编码转换
                [[NSUserDefaults standardUserDefaults] setObject:stylePicNameUrl forKey:SKIN_IMG_URL_03];
                [strIconURL release];
            }
            else if([stylePicName isEqualToString:@"bg.png"])
            {
                //NSString * stylePicId = @"4028818f3da54bed013da58ce1ef0001";
                NSString *strBackgroundURL=[[NSString alloc]initWithFormat:@"%@",[dicskin objectForKey:@"stylePicId"]];
                stylePicNameUrl=[NSString stringWithFormat:@"%@%@",Image_Url,strBackgroundURL];
                stylePicNameUrl = [stylePicNameUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];//字符串编码转换
                [[NSUserDefaults standardUserDefaults] setObject:stylePicNameUrl forKey:SKIN_IMG_URL_04];
                [strBackgroundURL release];
            }
        }
        
        NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
        [accountDefaults setObject:@"重大节日皮肤" forKey:@"UserDefaultBgKindKey"];
        [self viewDidLoad];
        
//        ViewController * home = [[ViewController alloc]init];
//        [AppDelegate app].unc =nil;
//        [AppDelegate app].unc = [[UINavigationController alloc] initWithRootViewController:home];
//        [[AppDelegate app].window addSubview:[AppDelegate app].unc.view];
//        [[AppDelegate app].window makeKeyAndVisible];
    }
    else
    {
        [self justShowMessage:@"皮肤更新失败" title:@"注意"];
    }
}

- (void)ResponseUpdateFail:(ASIHTTPRequest *)request
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    NSLog(@"服务器连接失败!");
    [self justShowMessage:@"服务器连接失败" title:@"注意"];
}

-(void) ClickItem:(NSString *)Title selectRow:(NSInteger)SelectRow ActionSheetTag:(NSInteger)actionSheetTag
{
    if (actionSheetTag == 0)
    {
        NSString * contentstr = [NSString stringWithFormat:@"您已设置%@成功!",Title];
        [self justShowMessage:contentstr title:@"提示"];
        NSString * appbgtype = Title;
        NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
        [accountDefaults setObject:appbgtype forKey:UserDefaultBgKindKey];
        [self viewDidLoad];
    }
    else if(actionSheetTag == 1)
    {
        [self setSkinUpdateRequest:SelectRow];
    }
}

//-(void)ClickItem:(NSString *)Title ActionSheetTag:(NSInteger)actionSheetTag
//{
//    if (actionSheetTag == 0)
//    {
//        NSString * contentstr = [NSString stringWithFormat:@"您已设置%@成功!",Title];
//        [self justShowMessage:contentstr title:@"提示"];
//        NSString * appbgtype = Title;
//        NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
//        [accountDefaults setObject:appbgtype forKey:UserDefaultBgKindKey];
//        [self viewDidLoad];
//    }
//}

-(void) CheckIfAuto
{
    if (swichAutoStyle.on)
    {
        NSString * contentstr = [NSString stringWithFormat:@"您已设置自动更换主题风格成功!"];
        [self justShowMessage:contentstr title:@"提示"];
        NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
        [accountDefaults setObject:@"1" forKey:@"IF_SKIN_UPDATE"];
        [accountDefaults synchronize];
        
        [accountDefaults setObject:@"1" forKey:@"SKIN_SWITCH_STATUS"];
        [accountDefaults synchronize];
        /*NSString * appbgtype = @"重大节日皮肤";
        NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
        [accountDefaults setObject:appbgtype forKey:UserDefaultBgKindKey];*/
    }
    else
    {
        [self justShowMessage:@"您已设置手动更换主题风格成功!" title:@"提示"];
        NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
        [accountDefaults setObject:@"0" forKey:@"IF_SKIN_UPDATE"];
        [accountDefaults synchronize];
        
        [accountDefaults setObject:@"0" forKey:@"SKIN_SWITCH_STATUS"];
        [accountDefaults synchronize];
        //NSUserDefaults *accountDefaults1 = [NSUserDefaults standardUserDefaults];
        //[accountDefaults1 setObject:@"0" forKey:@"IF_ON"];
    }
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(void)dealloc
{
    [arrStyleName release];
    [arrStyleID release];
    [swichAutoStyle release];
    [TableViewSkin release];
    [PreviewImage release];
    [SkinType release];
    [super dealloc];
}
@end
